﻿using DevExpress.XtraEditors;
using DevTeam;
using System;
using System.Data;
using System.Drawing;

namespace ConfExpert.Forms.Planlama
{
    public partial class GomlekAktarimi : XPopupForm
    {
        DataTable dt;
        int DepoId;
        int EskiDepoId;
        int CarrierId;
        public GomlekAktarimi(DataTable dt, int DepoId, int EskiDepoId, int CarrierId)
        {
            InitializeComponent();
            this.dt = dt;
            this.DepoId = DepoId;
            this.EskiDepoId = EskiDepoId;
            this.CarrierId = CarrierId;
        }

        private void GomlekAktarimi_Load(object sender, EventArgs e)
        {
            //dt.Columns.Add("GirilecekAdet", typeof(int));
            gridView1.Init(dt);
            gridView1.MakeReadOnly("GirilebilirAdet");
            gridView1.MakeColumnInvisible("Seç", "GomlekStokId");
            gridView1.BestFitColumns();
            btnAktar.ItemClick += btnAktar_ItemClick;
            gridView1.RowCellStyle += gridView1_RowCellStyle;
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.Column.FieldName == "GirilebilirAdet")
            {
                e.Appearance.Font = new Font(DevExpress.Utils.AppearanceObject.DefaultFont, FontStyle.Bold);
            }
        }

        void btnAktar_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            for (int i = 0; i < gridView1.DataRowCount; i++)
            {
                if (gridView1.GetRowCellValue(i, "GirilebilirAdet").ToInt() > gridView1.GetRowCellValue(i, "Adet").ToInt())
                {
                    XtraMessageBox.Show("Depoya transfer edilecek gömlek sayısı, kesilen gömlek sayısından fazla olamaz!");
                    return;
                }
            }
            ExecuteNonQuery("UpdGomlekStok", dt.Serialize(), DepoId, EskiDepoId, CarrierId, WhoAmI);
            this.Close();
        }
    }
}
